package com.piao.springboot_interceptor.config;

import com.piao.springboot_interceptor.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class MyConfig implements WebMvcConfigurer {


    @Resource
    private LoginInterceptor loginInterceptor;

    //注册拦截器，springboot已经做好静态资源(js/css等)的映射，无需额外配置
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)//增加过滤的方法类
                .addPathPatterns("/**")//定义过滤的范围,拦截所有请求
                .excludePathPatterns("/", "/login");//
    }

    //配置默认跳转
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("login");// /请求跳转login
    }
}
